package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.beans.base.image;
import com.hdax.dm.beans.item.Item;
import com.hdax.dm.dto.IndexNavDto;
import com.hdax.dm.feign.imagefeign;
import com.hdax.dm.mappers.ItemMapper;
import com.hdax.dm.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements ItemService {

    @Autowired
    private imagefeign imagefeign;

    //    -----------------获取楼层数据---------------------
    @Override
    public List<IndexNavDto.HotItems> hotItems(Long ItemType1Id, Long isBanner) {
        List<Item> Items = baseMapper.items(ItemType1Id, isBanner);
        List<IndexNavDto.HotItems> hotItems = new ArrayList<>();
        Items.forEach(item->{
            IndexNavDto.HotItems dto = new IndexNavDto.HotItems();
            dto.setId(item.getId());
            dto.setItemName(item.getItemName());
            dto.setMinPrice(item.getMinPrice());

            /*item通过openfeign远程调用了base,查询图片信息*/
            image img= imagefeign.image(dto.getId(),2L,1L);
            String imgUrl= img == null ? "":img.getImgUrl();
            dto.setImgUrl(imgUrl);
            hotItems.add(dto);
        });
        return hotItems;
    }

    //    -----------------获取楼层内部数据---------------------
    @Override
    public List<Item> floor(Long itemType1Id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("itemType1Id",itemType1Id);
        queryWrapper.last("limit 5");
        List<Item> list = baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public Item item(Integer id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",id);
        return baseMapper.selectOne(queryWrapper);
    }
}
